package copyengine.utils.delayEffect.effect.basic.old
{
	import copyengine.utils.debug.CELog;

	import flash.display.DisplayObjectContainer;
	import copyengine.utils.delayEffect.effect.ICEDelayEffect;

	/**
	 * <b>当前Effect特性为:</b></br>
	 * <b>不包含子Child,主逻辑执行结束后及全部结束</b>
	 * </br></br>===========================</br></br>
	 * <b>所有Effect特性为:</b>
	 * <li>BasicEffect 					不包含子Child,可以Override,当Execute时候->主逻辑执行完成及为完成
	 * <li>MacroEffect 					包含子Child,不可以Override,当ExecuteBranch时候->所有子Child一同执行
	 * <li>ContianBranchEffect		包含子Child,可以Override,当ExecuteBranch时候->让所有Branch按顺序执行
	 * <li>SelectableChildEffect	包含子Child,可以Override,当ExecuteBranch时候->选择应该执行哪个Branch
	 */
	public class CEDelayEffectBasicOld implements ICEDelayEffect
	{
		public static const LAYER_TYPE_SCENE_UI:int = 1;
		public static const LAYER_TYPE_SCENE:int = 2;
		public static const LAYER_TYPE_GLOBAL_UI:int = 3;

		private var isFinishExecute:Boolean;

		private var isFinishExecuteHandleLogic:Boolean;

		protected var globalUILayer:DisplayObjectContainer;
		protected var sceneUILayer:DisplayObjectContainer;
		protected var sceneLayer:DisplayObjectContainer;

		private var flowFinishCallBack:Function;
		private var executeFinishCallBack:Function;

		public function CEDelayEffectBasicOld()
		{
		}

		public final function setLayer(_sceneUILayer:DisplayObjectContainer, _sceneLayer:DisplayObjectContainer, _globalUILayer:DisplayObjectContainer):void
		{
			globalUILayer = _globalUILayer;
			sceneUILayer = _sceneUILayer;
			sceneLayer = _sceneLayer;
		}

		public final function execute(_flowFinishCallBack:Function, _executeFinishCallBack:Function):void
		{
			flowFinishCallBack = _flowFinishCallBack;
			executeFinishCallBack = _executeFinishCallBack;

			doExecute();
		}

		public final function dispose():void
		{
			//先清空CallBack防止在doDispose函数中回调CallBack
			flowFinishCallBack = null;
			executeFinishCallBack = null;

			doDispose();
		}

		public final function isExecuteFinish():Boolean
		{
			return isFinishExecute;
		}

		protected final function onFlowFinish():void
		{
			flowFinishCallBack && flowFinishCallBack();
			flowFinishCallBack = null;
		}

		protected final function onExecuteFinish():void
		{
			isFinishExecute = true;
			tryToExecuteDataHandleLogic();
			executeFinishCallBack && executeFinishCallBack();
			executeFinishCallBack = null;
		}

		public final function finishExecuteImmediately():void
		{
			tryToExecuteDataHandleLogic();
		}

		private function tryToExecuteDataHandleLogic():void
		{
			if (!isFinishExecuteHandleLogic)
			{
				executeDataHandleLogic();
			}
			isFinishExecuteHandleLogic = true;
		}

		protected final function getLayerByType(_type:int):DisplayObjectContainer
		{
			if (_type == LAYER_TYPE_SCENE)
			{
				return sceneLayer;
			}
			else if (_type == LAYER_TYPE_SCENE_UI)
			{
				return sceneUILayer;
			}
			else if (_type == LAYER_TYPE_GLOBAL_UI)
			{
				return globalUILayer;
			}
			else
			{
				CELog.err("CEDelayEffectBasic-> can not find layer by type : " + _type);
				return null;
			}
		}

		//==================
		//==OverrideAble Function
		//==================

		public function onFlowExecuteFinish():void
		{
		}

		/**
		 * 执行数据处理相关的逻辑,如向DataHandle发送Notification等
		 */
		protected function executeDataHandleLogic():void
		{
		}

		protected function doExecute():void
		{
		}

		protected function doDispose():void
		{
		}

	}
}
